Skip to content

split param-string by escaping brackets to allow for type containing brackets#25

Open
louisdecharson wants to merge 1 commit into
emacs-vs:masterfrom
louisdecharson:master
Open

split param-string by escaping brackets to allow for type containing brackets#25
louisdecharson wants to merge 1 commit into
emacs-vs:masterfrom
louisdecharson:master

Conversation

@louisdecharson

Copy link
Copy Markdown

Types in Python might contain brackets and commas resulting in errors when parsing the parameters of the function.

Example

def foo(bar: Dict[str, Dict[str, str]]) -> Dict[str, Dict[str, str]]:
    pass

Results in
image

The PR creates a new function docstr--split-string-escape-brackets that split string while escaping the bracket to capture the full type:
image

@jcs090218

Copy link
Copy Markdown
Member

I don't think it will work since it will affect all other languages. Python is indeed one of the hardest languages to parse using regex. 😓

Another approach is ts-docstr, but it requires tree-sitter. The parsing task is a lot easier there, and it's fast and accurate. Here is the result from ts-docstr:

def foo(bar: Dic[str, Dict[str, str]]) -> Dict[str, Dict[str, str]]:
    """

    Parameters
    -------
    bar : Dic[str, Dict[str, str]]
        [description]

    Returns
    -------
        [description]
    """
    pass

@louisdecharson

Copy link
Copy Markdown
Author

Hi @jcs090218, thank you for the swift reply.
True that it will affect other languages but I think it's harmless as I cannot think of a programming language that would use unclosed brackets as part of a type or variable name - do you have an example in mind ?

Happy to use ts-docstr but it has some dependency to some niche packages like msgu which cannot be found on the usual Emacs lisp package archives.

@jcs090218

Copy link
Copy Markdown
Member

True that it will affect other languages but I think it's harmless as I cannot think of a programming language that would use unclosed brackets as part of a type or variable name - do you have an example in mind ?

I don't have an example in mind. Let me re-think this, and then I will get back to you!

Happy to use ts-docstr but it has some dependency to some niche packages like msgu which cannot be found on the usual Emacs lisp package archives.

msgu is under my own JCS-ELPA, including the package ts-docstr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants